package disenio

import modelo.Jugador
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.Label
import modelo.Planta
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.bindings.ObservableProperty
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.widgets.Button

class PlantarWindow extends Dialog<Jugador> {

	new(WindowOwner owner, Jugador jugador) {
		super(owner, jugador)
	}
	
	override protected createFormPanel(Panel mainPanel) {
		val form = new Panel(mainPanel)
		form.layout = new ColumnLayout(1)
		new Label(form).text = "Elija un planta"
		
		new Label(form).text = "Agua"
		
		val selectorPlantaAgua = new Selector<Planta>(form)
		selectorPlantaAgua.allowNull(false)
		selectorPlantaAgua.bindValueToProperty("plantaSeleccionada")
		var propiedadAgua = selectorPlantaAgua.bindItems(new ObservableProperty("jardinZenAgua"))
		propiedadAgua.adapter = new PropertyAdapter(typeof(Planta), "nombre")
		
		new Label(form).text = "Tierra"
		
		val selectorPlanta = new Selector<Planta>(form)
		selectorPlanta.allowNull(false)
		selectorPlanta.bindValueToProperty("plantaSeleccionada")
		var propiedadModelos = selectorPlanta.bindItems(new ObservableProperty("jardinZenTierra"))
		propiedadModelos.adapter = new PropertyAdapter(typeof(Planta), "nombre")
			
	}
	override protected void addActions(Panel actions) {
		new Button(actions)
			.setCaption("Plantar")
			.onClick [|this.plantar]
			.setAsDefault.disableOnError

		new Button(actions) //
			.setCaption("Cancelar")
			.onClick [|this.cancel]
	}
	
	def plantar() {
		modelObject.plantarUnaPlanta()
		this.accept
	}
	
}